/*******************************************************************************
 * Package: com.ruoyi.use.web
 * Type:    SetataWeb
 * Date:    2024-03-02 19:37
 *
 * Copyright (c) 2024 LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.ruoyi.use.web;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.system.api.RemoteProductService;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.use.mapper.ShopProductMapper;
import com.ruoyi.use.req.SeataReq;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.web.bind.annotation.*;



/**
 * 功能描述：调试seata
 * 分布式事务
 *
 * @author Songxianyang
 * @date 2024-03-02 19:37
 */
@Slf4j
@RestController
@RequestMapping("/use")
public class SeataWeb {

    @Resource
    private ShopProductMapper shopProductMapper;

    @Resource
    private RemoteProductService remoteProductService;

    @Resource
    private RemoteUserService remoteUserService;

    @Trace
    @PostMapping("/globalTransactional")
    @GlobalTransactional(name = "cherry-transactional-server",rollbackFor = Exception.class)
    public void get(@RequestBody SeataReq req) throws Exception {
        shopProductMapper.insertShopProduct(req.getShopProduct());
        remoteProductService.add(req.getShopProduct(), SecurityConstants.INNER);
        log.info("i的值{}",0);
        int i=100/0;
    }

    /**
     * 测试 nacos服务发现
     * @param id
     */
    @GetMapping("get-info")
    public void getInfo(Long id) {
        shopProductMapper.deleteShopProductById(id);
        remoteUserService.authRole(id);
    }
}
